home *** CD-ROM | disk | FTP | other *** search
/ C++ für Kids / C++ for kids.iso / SETUP / US / CBUILDER / DATA.Z / CLASSES.INT < prev    next >
Text File  |  1997-02-13  |  23KB  |  652 lines

  1.  
  2. {*******************************************************}
  3. {                                                       }
  4. {       Delphi Visual Component Library                 }
  5. {                                                       }
  6. {       Copyright (c) 1995-1997 Borland International   }
  7. {                                                       }
  8. {*******************************************************}
  9.  
  10. unit Classes;            // $Revision:   1.4  $
  11.  
  12. {$R-}
  13.  
  14. interface
  15.  
  16. uses SysUtils, Windows;
  17.  
  18. const
  19.  
  20. { Maximum TList size }
  21.  
  22.   MaxListSize = Maxint div 16;
  23.  
  24. { TStream seek origins }
  25.  
  26.   soFromBeginning = 0;
  27.   soFromCurrent = 1;
  28.   soFromEnd = 2;
  29.  
  30. { TFileStream create mode }
  31.  
  32.   fmCreate = $FFFF;
  33.  
  34. { TParser special tokens }
  35.  
  36.   toEOF     = Char(0);
  37.   toSymbol  = Char(1);
  38.   toString  = Char(2);
  39.   toInteger = Char(3);
  40.   toFloat   = Char(4);
  41.  
  42. type
  43.  
  44. { Text alignment types }
  45.  
  46.   TAlignment = (taLeftJustify, taRightJustify, taCenter);
  47.   TLeftRight = taLeftJustify..taRightJustify;
  48.  
  49. { Types used by standard events }
  50.  
  51.   TShiftState = set of (ssShift, ssAlt, ssCtrl,
  52.     ssLeft, ssRight, ssMiddle, ssDouble);
  53.  
  54.   THelpContext = -MaxLongint..MaxLongint;
  55.  
  56. { Standard events }
  57.  
  58.   TNotifyEvent = procedure(Sender: TObject) of object;
  59.   THelpEvent = function (Command: Word; Data: Longint;
  60.     var CallHelp: Boolean): Boolean of object;
  61.   TGetStrProc = procedure(const S: string) of object;
  62.  
  63. { Exception classes }
  64.  
  65.   EStreamError = class(Exception);
  66.   EFCreateError = class(EStreamError);
  67.   EFOpenError = class(EStreamError);
  68.   EFilerError = class(EStreamError);
  69.   EReadError = class(EFilerError);
  70.   EWriteError = class(EFilerError);
  71.   EClassNotFound = class(EFilerError);
  72.   EMethodNotFound = class(EFilerError);
  73.   EInvalidImage = class(EFilerError);
  74.   EResNotFound = class(Exception);
  75.   EListError = class(Exception);
  76.   EBitsError = class(Exception);
  77.   EStringListError = class(Exception);
  78.   EComponentError = class(Exception);
  79.   EParserError = class(Exception);
  80.  
  81. { Forward class declarations }
  82.  
  83.   TStream = class;
  84.   TFiler = class;
  85.   TReader = class;
  86.   TWriter = class;
  87.   TComponent = class;
  88.  
  89. { TList class }
  90.  
  91.   PPointerList = ^TPointerList;
  92.   TPointerList = array[0..MaxListSize - 1] of Pointer;
  93.   TListSortCompare = function (Item1, Item2: Pointer): Integer;
  94.  
  95.   TList = class(TObject)
  96.   protected
  97.     procedure Error; virtual;
  98.     function Get(Index: Integer): Pointer;
  99.     procedure Grow; virtual;
  100.     procedure Put(Index: Integer; Item: Pointer);
  101.     procedure SetCapacity(NewCapacity: Integer);
  102.     procedure SetCount(NewCount: Integer);
  103.   public
  104.     destructor Destroy; override;
  105.     function Add(Item: Pointer): Integer;
  106.     procedure Clear;
  107.     procedure Delete(Index: Integer);
  108.     procedure Exchange(Index1, Index2: Integer);
  109.     function Expand: TList;
  110.     function First: Pointer;
  111.     function IndexOf(Item: Pointer): Integer;
  112.     procedure Insert(Index: Integer; Item: Pointer);
  113.     function Last: Pointer;
  114.     procedure Move(CurIndex, NewIndex: Integer);
  115.     function Remove(Item: Pointer): Integer;
  116.     procedure Pack;
  117.     procedure Sort(Compare: TListSortCompare);
  118.     property Capacity: Integer;
  119.     property Count: Integer;
  120.     property Items[Index: Integer]: Pointer; default;
  121.     property List: PPointerList;
  122.   end;
  123.  
  124. { TBits class }
  125.  
  126.   TBits = class
  127.   public
  128.     destructor Destroy; override;
  129.     function OpenBit: Integer;
  130.     property Bits[Index: Integer]: Boolean; default;
  131.     property Size: Integer;
  132.   end;
  133.  
  134. { TPersistent abstract class }
  135.  
  136. {$M+}
  137.  
  138.   TPersistent = class(TObject)
  139.   protected
  140.     procedure AssignTo(Dest: TPersistent); virtual;
  141.     procedure DefineProperties(Filer: TFiler); virtual;
  142.   public
  143.     procedure Assign(Source: TPersistent); virtual;
  144.   end;
  145.  
  146. {$M-}
  147.  
  148. { TPersistent class reference type }
  149.  
  150.   TPersistentClass = class of TPersistent;
  151.  
  152. { TCollection class }
  153.  
  154.   TCollection = class;
  155.  
  156.   TCollectionItem = class(TPersistent)
  157.   protected
  158.     procedure Changed(AllItems: Boolean);
  159.     procedure SetIndex(Value: Integer); virtual;
  160.   public
  161.     constructor Create(Collection: TCollection); virtual;
  162.     destructor Destroy; override;
  163.     property Collection: TCollection;
  164.     property Index: Integer;
  165.   end;
  166.  
  167.   TCollectionItemClass = class of TCollectionItem;
  168.  
  169.   TCollection = class(TPersistent)
  170.   protected
  171.     procedure Changed;
  172.     function GetItem(Index: Integer): TCollectionItem;
  173.     procedure SetItem(Index: Integer; Value: TCollectionItem);
  174.     procedure Update(Item: TCollectionItem); virtual;
  175.   public
  176.     constructor Create(ItemClass: TCollectionItemClass);
  177.     destructor Destroy; override;
  178.     function Add: TCollectionItem;
  179.     procedure Assign(Source: TPersistent); override;
  180.     procedure BeginUpdate;
  181.     procedure Clear;
  182.     procedure EndUpdate;
  183.     property Count: Integer;
  184.     property Items[Index: Integer]: TCollectionItem;
  185.   end;
  186.  
  187. { TStrings class }
  188.  
  189.   TStrings = class(TPersistent)
  190.   protected
  191.     procedure DefineProperties(Filer: TFiler); override;
  192.     function Get(Index: Integer): string; virtual; abstract;
  193.     function GetCount: Integer; virtual; abstract;
  194.     function GetObject(Index: Integer): TObject; virtual;
  195.     function GetTextStr: string; virtual;
  196.     procedure Put(Index: Integer; const S: string); virtual;
  197.     procedure PutObject(Index: Integer; AObject: TObject); virtual;
  198.     procedure SetTextStr(const Value: string); virtual;
  199.     procedure SetUpdateState(Updating: Boolean); virtual;
  200.   public
  201.     function Add(const S: string): Integer; virtual;
  202.     function AddObject(const S: string; AObject: TObject): Integer; virtual;
  203.     procedure Append(const S: string);
  204.     procedure AddStrings(Strings: TStrings); virtual;
  205.     procedure Assign(Source: TPersistent); override;
  206.     procedure BeginUpdate;
  207.     procedure Clear; virtual; abstract;
  208.     procedure Delete(Index: Integer); virtual; abstract;
  209.     procedure EndUpdate;
  210.     function Equals(Strings: TStrings): Boolean;
  211.     procedure Exchange(Index1, Index2: Integer); virtual;
  212.     function GetText: PChar; virtual;
  213.     function IndexOf(const S: string): Integer; virtual;
  214.     function IndexOfName(const Name: string): Integer;
  215.     function IndexOfObject(AObject: TObject): Integer;
  216.     procedure Insert(Index: Integer; const S: string); virtual; abstract;
  217.     procedure InsertObject(Index: Integer; const S: string;
  218.       AObject: TObject);
  219.     procedure LoadFromFile(const FileName: string); virtual;
  220.     procedure LoadFromStream(Stream: TStream); virtual;
  221.     procedure Move(CurIndex, NewIndex: Integer); virtual;
  222.     procedure SaveToFile(const FileName: string); virtual;
  223.     procedure SaveToStream(Stream: TStream); virtual;
  224.     procedure SetText(Text: PChar); virtual;
  225.     property CommaText: string;
  226.     property Count: Integer;
  227.     property Names[Index: Integer]: string;
  228.     property Objects[Index: Integer]: TObject;
  229.     property Values[const Name: string]: string;
  230.     property Strings[Index: Integer]: string; default;
  231.     property Text: string;
  232.   end;
  233.  
  234. { TStringList class }
  235.  
  236.   TDuplicates = (dupIgnore, dupAccept, dupError);
  237.  
  238.   PStringItem = ^TStringItem;
  239.   TStringItem = record
  240.     FString: string;
  241.     FObject: TObject;
  242.   end;
  243.  
  244.   PStringItemList = ^TStringItemList;
  245.   TStringItemList = array[0..MaxListSize] of TStringItem;
  246.  
  247.   TStringList = class(TStrings)
  248.   protected
  249.     procedure Changed; virtual;
  250.     procedure Changing; virtual;
  251.     function Get(Index: Integer): string; override;
  252.     function GetCount: Integer; override;
  253.     function GetObject(Index: Integer): TObject; override;
  254.     procedure Put(Index: Integer; const S: string); override;
  255.     procedure PutObject(Index: Integer; AObject: TObject); override;
  256.     procedure SetUpdateState(Updating: Boolean); override;
  257.   public
  258.     destructor Destroy; override;
  259.     function Add(const S: string): Integer; override;
  260.     procedure Clear; override;
  261.     procedure Delete(Index: Integer); override;
  262.     procedure Exchange(Index1, Index2: Integer); override;
  263.     function Find(const S: string; var Index: Integer): Boolean; virtual;
  264.     function